<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

</body>
</html>
<script>
    /**
     * 定时器
     */
    class myTimer {
        /**
         *
         * @param callback 回调函数
         * @param second 执行间隔时间ms
         */
        constructor(callback, second) {
            this.callback = callback;
            this.timer = null;
            this.second = second;
        }

        run() {
            this.timer = setInterval(this.callback, this.second)
        }

        stop() {
            clearInterval(this.timer)
            this.timer = null
        }
    }

    // 任务队列
    const list = []

    /**
     * 所有站点
     * @type {{bSite: {bSite: myTimer, name: string}, aSite: {aSite: myTimer, name: string}}}
     */
    const allSite = {
        aSite: {name: 'aSite', second: 1000},
        bSite: {name: 'bSite', second: 2000},
        cSite: {name: 'cSite', second: 2000},
        dSite: {name: 'dSite', second: 1000},
        eSite: {name: 'eSite', second: 2000},
    }

    const list = [a, b, c]

    const test = {
        a: ['http://a.com?page=1', 'http://a.com?page=2'],
        b: ['http://b.com?page=1', 'http://b.com?page=2'],
        c: ['http://c.com?page=1', 'http://c.com?page=2']
    }

    // 遍历出所有的站点名称
    const siteKey = Object.keys(allSite)

    // 站点增加定时器
    siteKey.forEach((item) => {
        allSite[item][item] = new myTimer(() => {
            if (!list.includes(item)) {
                console.log('add：' + item)
                list.push(item)
            }
        }, allSite[item].second)
    })

    // 开始任务
    siteKey.forEach(item => {
        allSite[item][item].run()
    })

    // 增加任务
    function add(data) {

    }

    setInterval(() => {
        list.shift()
        console.info(list)
        console.log(allSite)
    }, 4000)


    setTimeout(() => {
        const sitea = siteKey[0]
        console.log('停止a定时器: ' + sitea)
        allSite[sitea][sitea].stop()
    }, 10000)

</script>
